//
//  YMSystemAuthPopupView.swift
//  ViomiSystemAuth
//
//  Created by 陈狄夫 on 2021/5/12.
//

import Foundation
import VMUIKit
import Masonry

public typealias block = () -> ()

@objc public class YMSystemAuthPopupView : VMUIPopupView {
    public var cancelClicked : block? = nil
    public var submitClicked : block? = nil
    
    
    override public func setupInterface() {
        
        let titleLab = UILabel.init()
        titleLab.text = "权限弹窗title"
        titleLab.textColor = UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1)
        titleLab.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.regular)
        self.addSubview(titleLab)
        titleLab.mas_makeConstraints { (make) in
            make?.centerX.equalTo()(self)
            make?.top.equalTo()(self)?.offset()(20.0)
            make?.height.mas_equalTo()(22.0)
        }
        
        
        let contentLab = UILabel.init()
        contentLab.text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        contentLab.numberOfLines = 0
        contentLab.textAlignment = .left
        contentLab.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium)
        contentLab.textColor = UIColor(red: 17/255.0, green: 17/255.0, blue: 17/255.0, alpha: 1)
        self.addSubview(contentLab)
        contentLab .mas_makeConstraints { (make) in
            make?.top.equalTo()(self)?.offset()(60.0)
            make?.centerX.equalTo()(self)
            make?.width.lessThanOrEqualTo()(UIScreen.main.bounds.size.width - 20)
        }
        
        let cancelBtn = UIButton.init(type: .custom)
        cancelBtn.setTitle("取消", for: UIControl.State.normal)
        cancelBtn.setTitle("取消", for: UIControl.State.highlighted)
        cancelBtn.setTitleColor(UIColor(red: 153/255.0, green: 153/255.0, blue: 153/255.0, alpha: 1.0), for: UIControl.State.normal)
        cancelBtn.setTitleColor(UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0), for: UIControl.State.highlighted)
        cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular)
        cancelBtn.titleLabel?.textAlignment = .center
        cancelBtn.addTarget(self, action: #selector(cancelBtnClicked(button : )), for: .touchUpInside)
        
        let submitBtn = UIButton.init(type: .custom)
        submitBtn.setTitle("确定", for: UIControl.State.normal)
        submitBtn.setTitle("确定", for: UIControl.State.highlighted)
        submitBtn.setTitleColor(UIColor(red: 40/255.0, green: 190/255.0, blue: 202/255.0, alpha: 1.0), for: UIControl.State.normal)
        submitBtn.setTitleColor(UIColor(red: 40/255.0, green: 190/255.0, blue: 202/255.0, alpha: 1.0), for: UIControl.State.highlighted)
        submitBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular)
        submitBtn.titleLabel?.textAlignment = .center
        submitBtn.addTarget(self, action: #selector(submitBtnClicked(button : )), for: .touchUpInside)
        
        self.addSubview(cancelBtn)
        self.addSubview(submitBtn)
        
        cancelBtn.mas_makeConstraints { (make) in
            make?.left.equalTo()(self)
            make?.bottom.equalTo()(self)
            make?.height.mas_equalTo()(48.0)
        }
        
        submitBtn.mas_makeConstraints { (make) in
            make?.left.equalTo()(cancelBtn.mas_right)
            make?.right.equalTo()(self)
            make?.width.height()?.top()?.equalTo()(cancelBtn)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override public init(config: VMUIBasePopupViewConfig) {
        super.init(config: config)
    }
    
    override public init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    override public init(frame: CGRect, config: VMUIBasePopupViewConfig) {
        super.init(frame: frame, config: config)
    }
    
    @objc func cancelBtnClicked(button:UIButton) {
        if self.cancelClicked != nil {
            self.cancelClicked!()
        }
        self.dismiss()
    }
    
    @objc func submitBtnClicked(button:UIButton)  {
        if self.submitClicked != nil {
            self.submitClicked!()
        }
        self.dismiss()
    }

}
